package cn.stronglink.asset.message.mq.consumer;


import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.stronglink.asset.message.mq.consumer.jdEntity.AccessControlReceiverData;
import cn.stronglink.asset.message.mq.consumer.jdEntity.OutOfStorage;
import cn.stronglink.asset.module.assetmanage.out.service.OutService;

@Component("jdAccessControlReceiver")
public class JdAccessControlReceiver implements MessageListener{  
	private static final Logger logger = LoggerFactory.getLogger(JdAccessControlReceiver.class);
	@Autowired
	private OutService outService;
	
	public void onMessage(Message message) {
		try {
			if (!(message instanceof ActiveMQTextMessage)) {
				return;
			}
			TextMessage tm = (TextMessage) message;
			String msg = tm.getText();
			AccessControlReceiverData bm = JSON.parseObject(msg, AccessControlReceiverData.class);
			String actionCode = bm.getActioncode();
			if("collect020".equals(actionCode)){
				logger.info("**********接收到出入库logger的数据："+bm.getAwsPostdata().toString());
				OutOfStorage storage = JSONObject.parseObject(bm.getAwsPostdata().toString(), OutOfStorage.class);
				outService.receiveOutOfStorageData(storage);
			}
			
		} catch (JMSException e) {
			e.printStackTrace();
		}

	}
}
